import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import product from '@/components/product'
import news from '@/components/news'
import video from '@/components/video'
import jobs from '@/components/jobs'
import about from '@/components/about'
import prodetail from '@/components/prodetail'
import news_artical from '@/components/news_artical'
import video_detail from '@/components/video_detail'
// import sort1 from '@/components/product/sort1'
// import sort2 from '@/components/product/sort2'

Vue.use(Router)

const router = new Router({
  linkActiveClass: 'active',
  linkExactActiveClass: 'active',
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/index',
      meta:{title:'首页'}
    },
    {
      path:'/index',
      name:'index',
      component:index,
      meta:{title:'首页'}
    },
    {
      path:'/product',
      name:'product',
      component:product,
      meta:{title:'产品介绍'},
      
      // children: [
      //   {
      //     path:'/',
      //     name:'sort1',
      //     component:sort1
      //   },
        
      //   {
      //     path:'/sort2',
      //     name:'sort2',
      //     component:sort2
      //   }
      // ]
    },
    {
      path:'/news',
      name:'news',
      component:news,
      meta:{title:'新闻资讯'}      
    },
    {
      path:'/jobs',
      name:'jobs',
      component:jobs,
      meta:{title:'招贤纳士'}      
    },
    {
      path:'/about',
      name:'about',
      component:about,
      meta:{title:'关于我们'}
    },
    {
      path:'/video',
      name:'video',
      component:video,
      meta:{title:'视频'}
    },
    {
      path:'/news_artical/:id',
      name:'news_artical',
      component:news_artical
    },
    {
      path:'/prodetail/:id',
      name:'prodetail',
      component:prodetail
    },
    {
      path:'/video_detail/:id',
      name:'video_detail',
      component:video_detail
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})

// router.beforeEach((to, from, next) => {
//   let documentTitle = '天化云';

//   // path 是多级的，遍历
//   to.matched.forEach((path) => {
//     if (path.meta.title) {
//       documentTitle += ` - ${path.meta.title}`;
//     }
//   });

//   document.title = documentTitle;
//   next();
// });


export default router